<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li class="active"><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01.1 -r/--range ">1.1 -r/--range </a></li><li><a href="#t12. 多语言切换">2. 多语言切换</a></li><li><a href="#t23. 图片防盗链">3. 图片防盗链</a></li><li><a href="#t34. 代理服务器">4. 代理服务器</a></li><li><a href="#t45. 虚拟主机">5. 虚拟主机</a></li><li><a href="#t56. User-Agent">6. User-Agent</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <p>&#xFEFF;## 1. &#x9759;&#x6001;&#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;</p>
<ol>
<li><a href="https://gitee.com/zhufengnodejs/zf-server/commit/f364e32c0d3a1b65a671af946fd13a5363032f65">&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5668;</a></li>
<li><a href="https://gitee.com/zhufengnodejs/zf-server/commit/246b6868a77f721816b5a35fdb7fd2f53d5e303f">&#x5B9E;&#x73B0;&#x538B;&#x7F29;</a></li>
<li><a href="https://gitee.com/zhufengnodejs/zf-server/commit/81c2515ebfd475d88d521c68769c498369afb6f6">&#x5B9E;&#x73B0;&#x7F13;&#x5B58;</a></li>
<li><a href="https://gitee.com/zhufengnodejs/zf-server/commit/89656a75d7e79aa42b5f0528aee45d5286fc502f">&#x5B9E;&#x73B0;&#x65AD;&#x70B9;&#x7EED;&#x4F20;</a></li>
<li><a href="https://gitee.com/zhufengnodejs/zf-server/commit/e3897cb4b92b1e9b8fc22cec47edc75eaee25e5a">&#x53D1;&#x5E03;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;</a></li>
</ol>
<p><a href="https://gitee.com/zhufengnodejs/zf-server">&#x9759;&#x6001;&#x8D44;&#x6E90;&#x670D;&#x52A1;&#x5668;</a></p>
<h3 id="t01.1 -r/--range ">1.1 -r/--range  <a href="#t01.1 -r/--range "> # </a></h3>
<ul>
<li>&#x8BE5;&#x9009;&#x9879;&#x6307;&#x5B9A;&#x4E0B;&#x8F7D;&#x5B57;&#x8282;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x5E38;&#x5E94;&#x7528;&#x4E8E;&#x5206;&#x5757;&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;</li>
<li>range&#x7684;&#x8868;&#x793A;&#x65B9;&#x5F0F;&#x6709;&#x591A;&#x79CD;&#xFF0C;&#x5982;100-500&#xFF0C;&#x5219;&#x6307;&#x5B9A;&#x4ECE;100&#x5F00;&#x59CB;&#x7684;400&#x4E2A;&#x5B57;&#x8282;&#x6570;&#x636E;&#xFF1B;-500&#x8868;&#x793A;&#x6700;&#x540E;&#x7684;500&#x4E2A;&#x5B57;&#x8282;&#xFF1B;5000-&#x8868;&#x793A;&#x4ECE;&#x7B2C;5000&#x4E2A;&#x5B57;&#x8282;&#x5F00;&#x59CB;&#x7684;&#x6240;&#x6709;&#x5B57;&#x8282;</li>
<li>&#x53E6;&#x5916;&#x8FD8;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x6307;&#x5B9A;&#x591A;&#x4E2A;&#x5B57;&#x8282;&#x5757;&#xFF0C;&#x4E2D;&#x95F4;&#x7528;&quot;,&quot;&#x5206;&#x5F00;</li>
<li>&#x670D;&#x52A1;&#x5668;&#x544A;&#x8BC9;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;range <code>response.setHeader(&apos;Accept-Ranges&apos;, &apos;bytes&apos;)</code></li>
<li>Server&#x901A;&#x8FC7;&#x8BF7;&#x6C42;&#x5934;&#x4E2D;&#x7684;<code>Range: bytes=0-xxx</code>&#x6765;&#x5224;&#x65AD;&#x662F;&#x5426;&#x662F;&#x505A;Range&#x8BF7;&#x6C42;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x503C;&#x5B58;&#x5728;&#x800C;&#x4E14;&#x6709;&#x6548;&#xFF0C;&#x5219;&#x53EA;&#x53D1;&#x56DE;&#x8BF7;&#x6C42;&#x7684;&#x90A3;&#x90E8;&#x5206;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF0C;&#x54CD;&#x5E94;&#x7684;&#x72B6;&#x6001;&#x7801;&#x53D8;&#x6210;206,&#x5982;&#x679C;&#x65E0;&#x6548;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;416&#x72B6;&#x6001;&#x7801;&#xFF0C;&#x8868;&#x660E;Request Range Not Satisfiable<pre><code class="lang-s">curl -r 0-1024 -o music.mp3
</code></pre>
</li>
</ul>
<h2 id="t12. &#x591A;&#x8BED;&#x8A00;&#x5207;&#x6362;">2. &#x591A;&#x8BED;&#x8A00;&#x5207;&#x6362; <a href="#t12. &#x591A;&#x8BED;&#x8A00;&#x5207;&#x6362;"> # </a></h2>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;Accept-Language&#x68C0;&#x6D4B;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x8BED;&#x8A00;</p>
<ul>
<li>&#x8BF7;&#x6C42;&#x5934;&#x683C;&#x5F0F; Accept-Language: Accept-Language:zh-CN,zh;q=0.9</li>
<li>&#x54CD;&#x5E94;&#x5934;&#x683C;&#x5F0F; Content-Language:zh-CN</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>);
<span class="hljs-keyword">let</span> pack = {
    <span class="hljs-attr">en</span>: {
        <span class="hljs-attr">title</span>: <span class="hljs-string">&apos;hello&apos;</span>
    },
    <span class="hljs-attr">cn</span>: {
        <span class="hljs-attr">title</span>: <span class="hljs-string">&apos;&#x6B22;&#x8FCE;&apos;</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">request</span>(<span class="hljs-params">req, res</span>) </span>{
    <span class="hljs-keyword">let</span> acceptLangulage = req.headers[<span class="hljs-string">&apos;accept-language&apos;</span>];
    <span class="hljs-keyword">let</span> lan = <span class="hljs-string">&apos;en&apos;</span>;
    <span class="hljs-keyword">if</span> (acceptLangulage) {
        lan = acceptLangulage.split(<span class="hljs-string">&apos;,&apos;</span>).map(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> {
            <span class="hljs-keyword">let</span> values = item.split(<span class="hljs-string">&apos;;&apos;</span>);
            <span class="hljs-keyword">return</span> {
                <span class="hljs-attr">name</span>: values[<span class="hljs-number">0</span>].split(<span class="hljs-string">&apos;-&apos;</span>)[<span class="hljs-number">0</span>],
                <span class="hljs-attr">q</span>: <span class="hljs-built_in">isNaN</span>(values[<span class="hljs-number">1</span>]) ? <span class="hljs-number">1</span> : <span class="hljs-built_in">parseInt</span>(values[<span class="hljs-number">1</span>])
            }
        }).sort(<span class="hljs-function">(<span class="hljs-params">lan1, lan2</span>) =&gt;</span> lan1.q - lan2.q).shift().name;
    }
    res.end(pack[lan] ? pack[lan].title : pack[<span class="hljs-string">&apos;en&apos;</span>].title);

}
<span class="hljs-keyword">let</span> server = http.createServer();
server.on(<span class="hljs-string">&apos;request&apos;</span>, request);
server.listen(<span class="hljs-number">8080</span>);
</code></pre>
<h2 id="t23. &#x56FE;&#x7247;&#x9632;&#x76D7;&#x94FE;">3. &#x56FE;&#x7247;&#x9632;&#x76D7;&#x94FE; <a href="#t23. &#x56FE;&#x7247;&#x9632;&#x76D7;&#x94FE;"> # </a></h2>
<ul>
<li>&#x4ECE;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#x8DF3;&#x8F6C;&#xFF0C;&#x6216;&#x8005;&#x7F51;&#x9875;&#x5F15;&#x7528;&#x5230;&#x67D0;&#x4E2A;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x65F6;&#xFF0C;HTTP&#x8BF7;&#x6C42;&#x4E2D;&#x5E26;&#x6709;Referer&#x8868;&#x793A;&#x6765;&#x6E90;&#x7F51;&#x9875;&#x7684;URL</li>
<li>&#x901A;&#x8FC7;&#x68C0;&#x67E5;&#x8BF7;&#x6C42;&#x5934;&#x4E2D;&#x7684;Referer&#x6765;&#x5224;&#x65AD;&#x6765;&#x6E90;&#x7F51;&#x9875;&#x7684;&#x57DF;&#x540D;</li>
<li>&#x5982;&#x679C;&#x6765;&#x6E90;&#x57DF;&#x540D;&#x4E0D;&#x5728;&#x767D;&#x540D;&#x5355;&#x5185;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x9519;&#x8BEF;&#x63D0;&#x793A;</li>
<li>&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;&#x56FE;&#x7247;&#x5730;&#x5740;&#x662F;&#x6CA1;&#x6709;referer&#x7684;</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>);
<span class="hljs-keyword">let</span> url = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;url&apos;</span>);
<span class="hljs-keyword">let</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">let</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-keyword">let</span> root = path.join(__dirname, <span class="hljs-string">&apos;public&apos;</span>);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">removePort</span>(<span class="hljs-params">host</span>) </span>{
    <span class="hljs-keyword">return</span> host.split(<span class="hljs-string">&apos;:&apos;</span>)[<span class="hljs-number">0</span>]
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getHostName</span>(<span class="hljs-params">urlAddr</span>) </span>{
    <span class="hljs-keyword">let</span> {
        host
    } = url.parse(urlAddr);
    <span class="hljs-keyword">return</span> removePort(host);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">request</span>(<span class="hljs-params">req, res</span>) </span>{
    <span class="hljs-keyword">let</span> refer = req.headers[<span class="hljs-string">&apos;referer&apos;</span>] || req.headers[<span class="hljs-string">&apos;referrer&apos;</span>];
    <span class="hljs-keyword">if</span> (refer) {
        <span class="hljs-keyword">let</span> referHost = getHostName(refer);
        <span class="hljs-keyword">let</span> host = removePort(req.headers[<span class="hljs-string">&apos;host&apos;</span>]);
        <span class="hljs-keyword">if</span> (referHost != host) {
            sendForbidden(req, res);
        } <span class="hljs-keyword">else</span> {
            serve(req, res);
        }
    } <span class="hljs-keyword">else</span> {
        serve(req, res);
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">serve</span>(<span class="hljs-params">req, res</span>) </span>{
    <span class="hljs-keyword">let</span> {
        pathname
    } = url.parse(req.url);
    <span class="hljs-keyword">let</span> filepath = path.join(root, pathname);
    <span class="hljs-built_in">console</span>.log(req.url, filepath);

    fs.stat(filepath, (err, stat) =&gt; {
        <span class="hljs-keyword">if</span> (err) {
            res.end(<span class="hljs-string">&apos;Not Found&apos;</span>);
        } <span class="hljs-keyword">else</span> {
            fs.createReadStream(filepath).pipe(res);
        }
    });
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sendForbidden</span>(<span class="hljs-params">req, res</span>) </span>{
    res.end(<span class="hljs-string">&apos;&#x9632;&#x76D7;&#x94FE;&apos;</span>);
}
<span class="hljs-keyword">let</span> server = http.createServer();
server.on(<span class="hljs-string">&apos;request&apos;</span>, request);
server.listen(<span class="hljs-number">8080</span>);
<span class="hljs-comment">//-H &quot;referer: http://xxx.xxx.xxx.xxx&quot;   http://localhost:8080/mv.jpg</span>
</code></pre>
<h2 id="t34. &#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;">4. &#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668; <a href="#t34. &#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;"> # </a></h2>
<p>&#x4EE3;&#x7406;&#xFF08;&#x82F1;&#x8BED;&#xFF1A;Proxy&#xFF09;&#xFF0C;&#x4E5F;&#x79F0;&#x7F51;&#x7EDC;&#x4EE3;&#x7406;&#xFF0C;&#x662F;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x7F51;&#x7EDC;&#x670D;&#x52A1;&#xFF0C;&#x5141;&#x8BB8;&#x4E00;&#x4E2A;&#x7F51;&#x7EDC;&#x7EC8;&#x7AEF;&#xFF08;&#x4E00;&#x822C;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#xFF09;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x670D;&#x52A1;&#x4E0E;&#x53E6;&#x4E00;&#x4E2A;&#x7F51;&#x7EDC;&#x7EC8;&#x7AEF;&#xFF08;&#x4E00;&#x822C;&#x4E3A;&#x670D;&#x52A1;&#x5668;&#xFF09;&#x8FDB;&#x884C;&#x975E;&#x76F4;&#x63A5;&#x7684;&#x8FDE;&#x63A5;&#x3002;&#x4E00;&#x4E9B;&#x7F51;&#x5173;&#x3001;&#x8DEF;&#x7531;&#x5668;&#x7B49;&#x7F51;&#x7EDC;&#x8BBE;&#x5907;&#x5177;&#x5907;&#x7F51;&#x7EDC;&#x4EE3;&#x7406;&#x529F;&#x80FD;&#x3002;&#x4E00;&#x822C;&#x8BA4;&#x4E3A;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x6709;&#x5229;&#x4E8E;&#x4FDD;&#x969C;&#x7F51;&#x7EDC;&#x7EC8;&#x7AEF;&#x7684;&#x9690;&#x79C1;&#x6216;&#x5B89;&#x5168;&#xFF0C;&#x9632;&#x6B62;&#x653B;&#x51FB;&#x3002;</p>
<pre><code class="lang-javascript">npm install http-proxy --save
</code></pre>
<ul>
<li>web &#x4EE3;&#x7406;&#x666E;&#x901A;&#x7684;HTTP&#x8BF7;&#x6C42;</li>
<li>listen port </li>
<li>close &#x5173;&#x95ED;&#x5185;&#x7F6E;&#x7684;&#x670D;&#x52A1;</li>
</ul>
<p><a href="https://www.npmjs.com/package/http-proxy">https://www.npmjs.com/package/http-proxy</a></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> httpProxy = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http-proxy&apos;</span>);
<span class="hljs-keyword">let</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>);
<span class="hljs-keyword">let</span> proxy = httpProxy.createProxyServer();

http.createServer(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req, res</span>) </span>{
    proxy.web(req, res, {
        <span class="hljs-attr">target</span>: <span class="hljs-string">&apos;http://localhost:8000&apos;</span>
    });
    proxy.on(<span class="hljs-string">&apos;error&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x51FA;&#x9519;&#x4E86;&apos;</span>);
        res.end(err.toString());
    });
}).listen(<span class="hljs-number">8080</span>);
</code></pre>
<h2 id="t45. &#x865A;&#x62DF;&#x4E3B;&#x673A;">5. &#x865A;&#x62DF;&#x4E3B;&#x673A; <a href="#t45. &#x865A;&#x62DF;&#x4E3B;&#x673A;"> # </a></h2>
<p>&#x901A;&#x8FC7;Host&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x7F51;&#x7AD9;&#x5171;&#x7528;&#x4E00;&#x4E2A;&#x7AEF;&#x53E3;,&#x591A;&#x4E2A;&#x7F51;&#x7AD9;&#x5171;&#x7528;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5668;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http&apos;</span>);
<span class="hljs-keyword">let</span> httpProxy = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;http-proxy&apos;</span>);
<span class="hljs-keyword">let</span> proxy = httpProxy.createProxyServer();

<span class="hljs-keyword">let</span> hosts = {
    <span class="hljs-string">&apos;a.zfpx.cn&apos;</span>: <span class="hljs-string">&apos;http://localhost:8000&apos;</span>,
    <span class="hljs-string">&apos;b.zfpx.cn&apos;</span>: <span class="hljs-string">&apos;http://localhost:9000&apos;</span>
}
<span class="hljs-keyword">let</span> server = http.createServer(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req, res</span>) </span>{
    <span class="hljs-keyword">let</span> host = req.headers[<span class="hljs-string">&apos;host&apos;</span>];
    host = host.split(<span class="hljs-string">&apos;:&apos;</span>)[<span class="hljs-number">0</span>];
    <span class="hljs-keyword">let</span> target = hosts[host];
    proxy.web(req, res, {
        target
    });

}).listen(<span class="hljs-number">80</span>);
</code></pre>
<h2 id="t56. User-Agent">6. User-Agent <a href="#t56. User-Agent"> # </a></h2>
<p>User Agent&#x4E2D;&#x6587;&#x540D;&#x4E3A;&#x7528;&#x6237;&#x4EE3;&#x7406;&#xFF0C;&#x7B80;&#x79F0; UA&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x5B57;&#x7B26;&#x4E32;&#x5934;&#xFF0C;&#x4F7F;&#x5F97;&#x670D;&#x52A1;&#x5668;&#x80FD;&#x591F;&#x8BC6;&#x522B;&#x5BA2;&#x6237;&#x4F7F;&#x7528;&#x7684;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x53CA;&#x7248;&#x672C;&#x3001;CPU &#x7C7B;&#x578B;&#x3001;&#x6D4F;&#x89C8;&#x5668;&#x53CA;&#x7248;&#x672C;&#x3001;&#x6D4F;&#x89C8;&#x5668;&#x6E32;&#x67D3;&#x5F15;&#x64CE;&#x3001;&#x6D4F;&#x89C8;&#x5668;&#x8BED;&#x8A00;&#x3001;&#x6D4F;&#x89C8;&#x5668;&#x63D2;&#x4EF6;&#x7B49;&#x3002;</p>
<ul>
<li>&#x8BF7;&#x6C42;&#x5934; User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36</li>
<li><code>user-agent-parser</code></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
